//优惠券列表

//获取父元素
var coupon_box=document.querySelector(".coupon_info");

fetch("http://chst.vip:1234/api/getcoupon").then(function(response){
    return response.json();
}).then(function(res){
    console.log(res);

    var txt="";
    res.result.forEach(item => {
        console.log(item);
        console.log(item.couponLink);
        
        
        txt += `<a href="#" couponid=${item.couponId}>
                    <img src="" alt="">
                    <p>${item.couponTitle}</p>
                </a>`

            console.log(txt);
    });
        coupon_box.innerHTML=txt;
        console.log(coupon_box);


       var abox=document.querySelectorAll(".coupon_info a");


       //事件委托
       abox.forEach(function(value){
            value.onclick=function(e){
                let target=e.target;

                    console.log(1);
                    let _this=target;
                    console.log(_this);
                    let id = _this.getAttribute('couponid')
                    console.log(id);

                    location.href="../pages/couponproduct.html?couponid="+id;
                    console.log(location.href);
            }
       })

        
})